package com._520it.crm.web.controller;

import com._520it.crm.domain.Institute;
import com._520it.crm.page.AjaxResult;
import com._520it.crm.page.PageResult;
import com._520it.crm.query.InstituteQueryObject;
import com._520it.crm.service.IInstituteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/institute")
public class InstituteController {
	@Autowired
	private IInstituteService instituteService;
	@RequestMapping("")
	public String index(){
		return "institute";
	}
	@RequestMapping("/list")
	@ResponseBody
	public PageResult list(InstituteQueryObject qo){
		PageResult result = instituteService.queryPage(qo);
		 return result;
	}
	//@RequiresPermissions("institute:save")
	//@PermissionName("学院新增")
	@RequestMapping("/save")
	@ResponseBody
	public AjaxResult save(Institute ins){
		AjaxResult result = null;
		try{
			instituteService.insert(ins);
			result = new AjaxResult(true,"保存成功");
		}catch(Exception e){
			e.printStackTrace();
			result = new AjaxResult("保存失败,请联系管理员!");
		}
		return result;
	}
	//@RequiresPermissions("institute:update")
	//@PermissionName("学院更新")
	@RequestMapping("/update")
	@ResponseBody
	public AjaxResult update(Institute ins){
		AjaxResult result = null;
		try{
			instituteService.updateByPrimaryKey(ins);
			result = new AjaxResult(true,"更新成功");
		}catch(Exception e){
			e.printStackTrace();
			result = new AjaxResult("更新失败,请联系管理员!");
		}
		return result;
	}
}
